package Demo2;

class MyRunnable implements Runnable {
    public void run () {
        while(true) {
            System.out.println("这是创建的线程");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new MyRunnable();

        Thread thread = new Thread(runnable);

        //启动线程
        thread.start();
        while(true) {
            System.out.println("这是主线程");
            Thread.sleep(1000);
        }
    }
}
